{ Siberian Olympiad. 3 stage.
  Problemset: http://agul-problems1.googlecode.com/svn/trunk/2010-2011/wso/stage3/wso_3stage.pdf
  Problem 2
  Points: 100
}
{$APPTYPE CONSOLE}
uses sysutils;
var l,k,i,n,kn,ln,c,j:longint; s,t,v,x:string; r:boolean;
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(l,k);
readln(s);
delete(s,1,1);
readln(n,kn,ln);
r:=false;
for I := 1 to n do begin
  readln(t);
  v:=copy(t,1,pos(' ',t)-1);
  delete(t,1,pos(' ',t));
  for j := 1 to k-1 do begin
    c:=0;
    while c<ln do begin
      delete(t,1,pos(' ',t));
      inc(c);
    end;
  end;
  for j := 1 to l-1 do delete(t,1,pos(' ',t));
  if pos(' ',t)<>0 then x:=copy(t,1,pos(' ',t)-1) else x:=t;
  if x=s then begin
    writeln(v);
    r:=true;
  end;
end;
if not r then writeln('NO');
end.